import java.util.StringJoiner;
import java.util.TreeMap;
import java.util.function.BiConsumer;

public class Tonhbv {
public static void main(String[] args){
    //1.定义字符串
    String s="aabbccdacaadcabb";

    TreeMap<Character,Integer> tm=new TreeMap<>();

    for (int i = 0; i < s.length(); i++) {
        char c=s.charAt(i);
        if (tm.containsKey(c)){
            int count=tm.get(c);
            count++;
            tm.put(c,count);
        }else {
            tm.put(c,1);
        }
    }
    System.out.println(tm);
    //遍历集合
    //3.1StringBuilder方法
    StringBuilder sb=new StringBuilder();
    tm.forEach(( key,  value)-> { sb.append(key).append("(").append(value).append(")"); });
    System.out.println(sb);
    //3.2StringJoiner
    StringJoiner sd=new StringJoiner("","","");
    tm.forEach(( key,  value)-> { sd.add(key+"").add("(").add(value+"").add(")"); });
    System.out.println(sd);

}

}
